import config from "@/config";
import API from '../../api'
import tool from '../../utils/tool'
export default {
	state: {
		//移动端布局
		ismobile: false,
		//布局
		layout: config.LAYOUT,
		//菜单是否折叠 toggle
		menuIsCollapse: config.MENU_IS_COLLAPSE,
		//多标签栏
		layoutTags: config.LAYOUT_TAGS,
		//主题
		theme: config.THEME,
		Enmu: {},
	},
	mutations: {
		SET_ismobile(state, key){
			state.ismobile = key
		},
		SET_layout(state, key){
			state.layout = key
		},
		SET_theme(state, key){
			state.theme = key
		},
		TOGGLE_menuIsCollapse(state){
			state.menuIsCollapse = !state.menuIsCollapse
		},
		TOGGLE_layoutTags(state){
			state.layoutTags = !state.layoutTags
		},
		SRT_ENMU(state, data){
			state.Enmu = data
		},
		
	},
	actions: {
		
		// 所有枚举类型
		getEnmuArr({commit}) {
			return new Promise((resolve, reject) => {
				API.auth.getEnmu.get().then(res=> {
					let info = res.data
					commit('SRT_ENMU', info)
					tool.data.set("ENMU", info)
					resolve(res)
				}).catch(error => {
					reject(error)
				})
			})
		},
		// 获取税区列表
		getTaxDistrict({commit}){
			return new Promise((resolve, reject) => {
				if(!tool.data.get("TAX_DISTRICT")){
					API.auth.getTaxDistrict.get().then(res=> {
						if(res.code === 0 && res.data){
							tool.data.set("TAX_DISTRICT", res.data)
						}
						resolve(res)
					}).catch(error => {
						reject(error)
					})
				}else{
					resolve()
				}
			})
		}
	}
}
